goog.provide('czk.ui.Checkbox');

goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.ui.Checkbox');
goog.require('goog.ui.Checkbox.State');

goog.require('czk.ui.ZKComponent');

/**
 * @constructor
 * @extends {czk.ui.ZKComponent}
 */
czk.ui.Checkbox = function() {
  goog.base(this);
  this.checkbox = new goog.ui.Checkbox();
};
goog.inherits(czk.ui.Checkbox, czk.ui.ZKComponent);

czk.ui.Checkbox.prototype.checkbox = null;

czk.ui.Checkbox.prototype.checked = null;

czk.ui.Checkbox.prototype.initialize =
    function(name, parameter, portlet, children) {
      goog.base(this, 'initialize', name, parameter, portlet, children);
      if (parameter['checked'])
        this.checked = parameter['checked'];
    };

czk.ui.Checkbox.prototype.createDom = function() {
  var dh = this.getDomHelper();
  var el = dh.createDom(goog.dom.TagName.DIV, {});
  this.setElementInternal(el);
  this.addChild(this.checkbox);
  this.checkbox.decorate(el);
  this.checkbox.setChecked(this.checked);
  // if (this.label)
  // this.checkbox.setLabel(this.label);

};

/** @inheritDoc */
czk.ui.Checkbox.prototype.enterDocument =
    function() {
      goog.base(this, 'enterDocument');
      this.getHandler().listen(this.checkbox,
          goog.ui.Component.EventType.CHANGE, this.change, false, this);

    };

czk.ui.Checkbox.prototype.change = function() {
  var data = '{"":' + this.checkbox.getChecked() + '}';
  this.portlet.sendXhr(this, 'onCheck', data);

};

czk.ui.Checkbox.prototype.handleZKResponseCommand = function(command) {
  goog.base(this, 'handleZKResponseCommand', command);
  if (command[0] == 'setAttr') {
    var attr = command[1][1];
    var val = command[1][2];
    if (attr == 'checked')
      this.checkbox.setChecked(val);
  }
};

czk.ui.Checkbox.create = function() {
  return new czk.ui.Checkbox();
};
